package ${r'${package}'}.controller;
import com.bolt.convention.data.ResultMessage;
import com.bolt.admin.common.base.BaseController;
import com.bolt.common.utils.StrUtil;
import ${r'${package}'}.entity.${table.className}Entity;
import ${r'${package}'}.service.${table.className}Service;
import ${r'${package}'}.dto.${table.className}DTO
import ${r'${package}'}.dto.converter.${table.className}Converter;
import com.bolt.convention.data.PageInfo;
import com.bolt.module.base.BaseService;
import com.bolt.support.spring.jpa.specification.QueryHelp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
* Auto Generate Javadoc
* @author
* 日期:${.now?string("yyyy-MM-dd HH:mm:ss")}
* ${table.remarks?default("")}
**/
@Controller
@RequestMapping("${url?default("/请修改URL")}")
public class ${table.className}Controller extends BaseController<${table.className}Entity,${table.pkColumn.javaType}> {

@Autowired
private ${table.className}Service ${table.className?uncap_first}Service;


/**
* 模块首页
*/
@RequestMapping(value = "", method = RequestMethod.GET)
public ModelAndView index(Model model, HttpServletRequest request) {
return super.index("${url?default("/请修改URL")}/index", request, model.asMap());
}

/**
* ${table.remarks}列表分页
* @return
*/
@RequestMapping(value = "page", method = RequestMethod.POST)
@ResponseBody
public ResultMessage list(Pageable pageable,${table.className}DTO dto) {
    PageInfo <${table.className}Entity> pageInfo =  ${table.className?uncap_first}Service.findPage(pageable,(root, criteriaQuery, criteriaBuilder)
    -> QueryHelp.getPredicate(root, dto, criteriaBuilder));
    return Returns.success(pageInfo.map(K -> ${table.className}Converter.toDTO(K)));

}

/**
*${table.remarks}新增操作
* @return
*/
@RequestMapping(value = "create", method = RequestMethod.GET)
public String create() {
return "${url?default("/请修改URL")}/input-index";
}

/**
* ${table.remarks?default("")}编辑页
* @param id    菜单ID
* @param model
* @return
*/
@RequestMapping(value = "edit", method = RequestMethod.GET)
public String edit(@RequestParam("id")  ${table.pkColumn.javaType} id, Model model) {
    ${table.className}Entity ${table.className?uncap_first}Entity = ${table.className?uncap_first}Service.findOne(id).get();
    model.addAttribute( Form.PAGECONTEXT_FORMVALUES,  ${table.className}Converter.toDTO(${table.className?uncap_first}Entity));
    return "${url?default("/请修改URL")}/input-index";
}

/**
* ${table.remarks?default("")}新增操作
* @param dao 表单数据
* @return
*/
@RequestMapping(value = "saveOrUpdate", method = RequestMethod.POST)
@ResponseBody
public ResultMessage saveOrUpdate(${table.className}DTO dao) {
    ${table.className?uncap_first}Service.saveOrUpdate(dao);
    return  Returns.success("保存成功");
}

/**
* ${table.remarks?default("")}删除操作
* @param id 菜单ID
* @return
*/
@RequestMapping(value = "del", method = RequestMethod.GET)
@ResponseBody
public ResultMessage doDelete(@RequestParam("id") ${table.pkColumn.javaType} id) {
    ${table.className?uncap_first}Service.deleteById(id);
    return  Returns.success("删除成功");
}


}